package cn.lf.android.lawfirm.inputsource.conntroller;

import android.content.Context;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.http.request.ParseManager;
import cn.lf.android.lawfirm.http.request.RequestManager;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.SPUtil;

/**
 * 录入案源controller
 * Created by Administrator on 2017/8/7.
 */

public class InputController extends BaseController{

    private InputCallback mInputCallback;
    private Context context;
    public InputController(InputCallback InputCallback, Context context) {
        this.mInputCallback = InputCallback;
        this.context = context;
    }

    /**
     * @param department                受理部门编号
     * @param brief                     简要描述
     * @param caseName                  案件名称
     * @param caseSourcePeople          案源人编号（如果为自定义案源人为空）
     * @param wtf                       拟委托方。格式为：委托方1ID（自定义-0）,委托方名称,委托方类型（单位-1/个人-2）,联系人名字,联系人电话/委托方2ID,委托方名称,委托方类型（单位/个人）,联系人名字,联系人电话
     * @param dfdsr                     对方当事人。以英文逗号分隔
     * @param sourceType                来源类型（值为：本所、非本所）
     * @param sysCaseDevelopPeopleInput 自定义案源人名字
     */
    public void onInput(String department, String brief, String caseName, String caseSourcePeople, String wtf, String dfdsr, String sourceType, String sysCaseDevelopPeopleInput) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        params.put("department", department);
        params.put("brief", brief);
        params.put("caseName", caseName);
        params.put("caseSourcePeople", caseSourcePeople);
        params.put("wtf", wtf);
        params.put("dfdsr", dfdsr);
        params.put("sourceType", sourceType);
        params.put("LsysCaseDevelopPeopleInput", sysCaseDevelopPeopleInput);
        SPUtil spUtil = new SPUtil(context);
        params.put("Authorization==",  spUtil.getAccessToken());
        DebugLog.e("department=="+department);
        DebugLog.e("brief=="+brief);
        DebugLog.e("caseName=="+caseName);
        DebugLog.e("caseSourcePeople=="+caseSourcePeople);
        DebugLog.e("wtf=="+wtf);
        DebugLog.e("dfdsr=="+dfdsr);
        DebugLog.e("sourceType=="+sourceType);
        DebugLog.e("LsysCaseDevelopPeopleInput=="+sysCaseDevelopPeopleInput);
        new MyOkHttpClient().doPost(AppConfig.CASEINFO, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("录入案源=="+response);
                        JSONObject myJsonObject;
                        Boolean isSuc;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                mInputCallback.onInputSuccessed("");
                            } else {
                                mInputCallback
                                        .onInputFailed("");
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        DebugLog.e("录入案源失败=="+errorMsg);
                        mInputCallback.onInputFailed(errorMsg);
                        dismissProgressDia();
                    }
                },"Authorization",spUtil.getAccessToken());
    }

    public interface InputCallback {
        public void onInputSuccessed(String str);

        public void onInputFailed(String errorMsg);
    }

}
